package io.renren.modules.generator.controller;

import java.util.List;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import io.renren.modules.generator.entity.DataLogEntity;
import io.renren.modules.generator.service.DataLogService;
import io.renren.common.utils.R;


/**
 * 海洋局data
 *
 * @author chenshun
 * @email sunlightcs@gmail.com
 * @date 2022-11-27 14:19:11
 */
@Slf4j
@Api("海洋局data解析")
@RestController
@RequestMapping("/datalog")
public class DataLogController {

    @Autowired
    private DataLogService dataLogService;

    /**
     * analysis
     */
    @ApiOperation("解析")
    @PutMapping("/analysis")
    public R analysis(){
        this.dataLogService.analysis();
        return R.ok();
    }


    /**
     * 使用sql语句查询获得time处于2022/9/24 9:40到2022/9/24 10:20之间的数据，并在此基础上查询显示ID频次最高的数据记录。
     */
    @ApiOperation("top记录")
    @GetMapping("/top")
    public R top(@RequestParam String startTime,@RequestParam String endTime){
        List<DataLogEntity> top = this.dataLogService.top(startTime, endTime);
        return R.ok().put("top",top);
    }


    /**
     * analysis
     */
    @ApiOperation("解析")
    @PutMapping("/work")
    public R work(){
        this.dataLogService.testTrancation();
        return R.ok();
    }
}
